<?php


namespace app\common\validate;


use think\Validate;

class AgentNewhouseValidate extends Validate {

    protected $rule =   [
        'qu_id'             => 'require|number',
        'salestatus'        => 'require',
        'lat'               => 'require',
        'lng'               => 'require',
        'title'             => 'require',
        'address'           => 'require',
        'unit_price'        => 'require',
        'small_area'        => 'require',
        'big_area'          => 'require',
        'housegreenrate'    => 'require',
        'houserate'         => 'require',
        'open_time'         => 'require',
        'housetype'         => 'require|checkTypeArrayLength',
        'special'           => 'require|checkSpecialArrayLength',
        'decorate'          => 'require|checkDecorateArrayLength',
        'housestyle'        => 'require|checkHousestyleArrayLength',
        'content'           => 'require',
        'thumbs'            => 'require|checkThumbsArrayLength',
    ];

    protected $message  =   [
        'qu_id.require'             => '请选择区域',
        'qu_id.number'              => '数据格式有误，请联系管理员',
        'salestatus.require'        => '请选择销售状态',
        'lat.require'               => '请选择位置',
        'lng.require'               => '请选择位置',
        'title.require'             => '请输入楼盘名称',
        'address.require'           => '请输入地址',
        'unit_price.require'        => '请输入单价',
        'small_area.require'        => '请输入最小面积',
        'big_area.require'          => '请输入最大面积',
        'housegreenrate.require'    => '请输入绿化率',
        'houserate.require'         => '请输入容积率',
        'open_time.require'         => '请输入开盘时间',
        'housetype.require'         => '请选择楼盘类型',
        'special.require'           => '请选楼盘特色',
        'decorate.require'          => '请选择装修',
        'housestyle.require'        => '请选择楼盘户型',
        'content.require'           => '请输入详情',
        'thumbs.require'            => '请上传楼盘图片',
    ];

    protected function checkDecorateArrayLength($value, $rule, $data=[]){
        if(!is_array($data['decorate'])){
            return '数据格式有误，请联系管理员';
        }
        if(sizeof($data['decorate'])==0){
            return '请选择房源类型';
        }
        return  true;
    }

    protected function checkHousestyleArrayLength($value, $rule, $data=[]){
        if(!is_array($data['housestyle'])){
            return '数据格式有误，请联系管理员';
        }
        if(sizeof($data['housestyle'])==0){
            return '请选择房源类型';
        }
        return  true;
    }

    protected function checkTypeArrayLength($value, $rule, $data=[]){
        if(!is_array($data['housetype'])){
            return '数据格式有误，请联系管理员';
        }
        if(sizeof($data['housetype'])==0){
            return '请选择房源类型';
        }
        return  true;
    }

    protected function checkSpecialArrayLength($value, $rule, $data=[]){
        if(!is_array($data['special'])){
            return '数据格式有误，请联系管理员';
        }
        if(sizeof($data['special'])==0){
            return '请选择房源特色';
        }
        return  true;
    }

    protected function checkThumbsArrayLength($value, $rule, $data=[]){
        if(!is_array($data['thumbs'])){
            return '数据格式有误，请联系管理员';
        }
        if(sizeof($data['thumbs'])==0){
            return '请上传房源图片';
        }
        return  true;
    }


}